package com.pronosticnews.client.util.dnd;

import com.google.gwt.user.client.ui.FlexTable;
import com.google.gwt.user.client.ui.HTML;
import com.google.gwt.user.client.ui.Widget;

/**
 * Table to demonstrate draggable rows and columns.
 */
public class DraggableFlexTable extends FlexTable {

  private FlexTableRowDragController tableRowDragController;

/**
   * Creates a FlexTable with the desired number of rows and columns, making each row draggable via
   * the provided drag controller.
   * 
   * @param rows desired number of table rows
   * @param cols desired number of table columns
   * @param tableRowDragController the drag controller to enable dragging of table rows
   */
  public DraggableFlexTable(int rows, int cols, FlexTableRowDragController tableRowDragController) {
	this.setTableRowDragController(tableRowDragController);
    addStyleName("demo-flextable");
    for (int row = 0; row < rows; row++) {
      HTML handle = new HTML("[drag-here]");
      handle.addStyleName("demo-drag-handle");
      setWidget(row, 0, handle);
      tableRowDragController.makeDraggable(handle);
      for (int col = 1; col < cols; col++) {
        setHTML(row, col, "[" + row + ", " + col + "]");
      }
    }
  }

public DraggableFlexTable(FlexTableRowDragController tableRowDragController) {
	this.tableRowDragController = tableRowDragController;
	addStyleName("demo-flextable");
}

public void addDraggableRow(String text, int col) {
	 HTML handle = new HTML(text);
	 int row = this.getRowCount();
	 setWidget(row, col, handle);
	 tableRowDragController.makeDraggable(handle);
}
 
public void addDraggableRow(Widget widget, int col) {
	 int row = this.getRowCount();
	 setWidget(row, col, widget);
	 tableRowDragController.makeDraggable(widget);
}
 



public FlexTableRowDragController getTableRowDragController() {
	return tableRowDragController;
}

public void setTableRowDragController(FlexTableRowDragController tableRowDragController) {
	this.tableRowDragController = tableRowDragController;
}
}
